﻿using System.Linq;
using FluentValidation;
using FluentValidation.Results;
using Giant.Admin.Models.Users;
using Giant.Core.Domain.Users;
using Giant.Data;
using Giant.Services.Localization;
using Giant.Web.Framework.Validators;

namespace Giant.Admin.Validators.Users
{
    public partial class UserValidator : BaseValidator<UserModel>
    {
        public UserValidator(ILocalizationService localizationService,
            UserSettings userSettings,
            IDbContext dbContext)
        {
            //form fields           
            
            if (userSettings.PhoneRequired && userSettings.PhoneEnabled)
                RuleFor(x => x.Phone).NotEmpty().WithMessage(localizationService.GetResource("Admin.Users.Users.Fields.Phone.Required"));
           
            SetStringPropertiesMaxLength<User>(dbContext);
        }
    }
}